package xc.com.ipscan;

import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import xc.com.ui.MainActivity;
import xc.com.wifi.dao.Wifi;

public class IpScanRunnable implements Runnable {
	private ExecutorService localExecutorService;

	private ArrayList<String> IP;
	private CountDownLatch latch;
	private MainActivity a;

	public IpScanRunnable(ArrayList<String> localArrayList,
			CountDownLatch latch, MainActivity mainActivity) {
		this.IP = localArrayList;
		this.latch = latch;
		this.a = mainActivity;
		localExecutorService = Executors.newCachedThreadPool();

	}

	@Override
	public void run() {
		if ((IP == null)) {
			return;

		} else {

			for (String str : IP) {
				if (IPutil.d(str)) {

					Wifi w = new Wifi();
					w.setWFip(str);
					w.setName(str);
					a.listTest.add(w);
					localExecutorService.execute(new AppName(w, a));
					a.mHandler.sendEmptyMessage(33);
					
				}

			}

		}
		latch.countDown();
	}

}
